<?php

namespace app\admin\model;

use app\admin\model\BaseModel;
use app\dic\DicOrder;

class Skucountdetail extends BaseModel
{

    protected $name = "skucountdetail";
    protected $pk = "id";

    protected $deleteTime = false;
    // 追加属性

    protected $append = [
        //订单时间
        'ordertime_title',
        //发货状态
        'delivery_status_title',
        'site_title',
    ];


    public function getOrdertimeTitleAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_time']) ? $data['order_time'] : time());
        return date('Y-m-d H:i:s', $value);
    }


    public function getDeliveryStatusTitleAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['delivery_status']) ? $data['delivery_status'] : '');
        $list = [DicOrder::$fulfillment_status_unfulfilled => '未完成', DicOrder::$fulfillment_status_fulfilled => '已发货'];
        return isset($list[$value]) ? $list[$value] : '未完成';
    }

    public function getSiteTitleAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['site']) ? $data['site'] : '');
        $site = table('site')->where(['id' => $data['site']])->find();
        return isset($site['site_name']) ? $site['site_name'] : '';
    }
}
